package com.itheima.controller;

import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import com.itheima.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author hu
 * @date 2025/3/9
 */
@RestController
@Slf4j
@RequestMapping("/students")
public class StudentControlller {

    @Resource
    private StudentService studentService;

    @GetMapping
    public Result listAll(StudentQueryParam queryParam) {
        log.info("=============接受请求参数:{}", queryParam.toString());
        PageResult<Student> students = studentService.listAll(queryParam);
        return Result.success(students);
    }

    @DeleteMapping("/{ids}")
    public Result del(@PathVariable List<Long> ids) {
        log.info("=============接受请求参数:{}", ids.toString());
        log.info("=============接受请求参数:{}", ids);
        studentService.delById(ids);
        return Result.success();
    }

    @PostMapping
    public Result add(@RequestBody Student student) {
        log.info("=============接受请求参数:{}", student);
        studentService.add(student);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result del(@PathVariable Integer id) {
        log.info("=============接受请求参数:{}", id);
        Student student = studentService.getById(id);
        return Result.success(student);
    }

    @PutMapping
    public Result update(@RequestBody Student student) {
        log.info("=============接受请求参数:{}", student);
        studentService.updateById(student);
        return Result.success();
    }

    @PutMapping("/violation/{id}/{score}")
    public Result violation(@PathVariable("id") Integer id,@PathVariable Integer score) {
        log.info("=============接受请求参数:{},{}", id,score);
        studentService.violation(id,score);
        return Result.success();
    }


}
